<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>   

<script type="text/javascript">
	$(document).ready(function(){
		$("#groupmemberBtn").click(function(){
			var gname=$("#gname").val();
			
			$.ajax({
				type : "post",
				url : "${initParam.root}/member/memberlist.do",
				data:"gname="+gname,
				datatype:"json",
				success:function(data){
				
					var str="<table class='table-wrapper'><thead><tr><td>ID</td><td>nick</td><td>Level</td><td>Tel</td></tr></thead>";
					$.each(data,function(index,strr){
						str+="<tr><td>"+strr.id+"</td><td>"+strr.nick+"</td><td>"+strr.level+"</td><td>"+strr.tel+"</td></tr>";
						//str+=strr.title;
					});
					str+="</table>";
					
					$("#groupmemberview").html(str);
				}
	    	});
		});
		$("#createGroupBtn").click(function(){
			if(!confirm("그룹 생성시 1000의 포인트가 감소합니다.생성 하시겠습니까?"))
				{
				return false;
				}
			var point=parseInt($("#point2").val());
			
			if( point<1000)
				{
				alert("포인트가 부족합니다");
				return false;
				}
			location.href="${initParam.root}/member/groupCreateView.do";
			
			
		});
		$("#manageGroupBtn").click(function(){
			if(confirm("그룹 관리 페이지로 이동 하시겠습니까?"))
			{
				location.href="${initParam.root}/member/groupUpdateView.do";
			}		
		});
	});
</script>

<h2>
<a href="${initParam.root}/member/mypageMyInfo.do">Mypage</a>
<a href="${initParam.root}/member/mypageMyGroup.do">내 그룹</a>
<a href="${initParam.root}/member/mypageMyPoint.do?id=${sessionScope.mvo.id }">내 포인트</a>
<a href="${initParam.root}/member/mypageUpdateView.do">회원정보수정</a>
<a href="${initParam.root}/member/mypageDeleteView.do">회원탈퇴</a>
</h2>

<br>



<c:choose>
	<c:when test="${sessionScope.mvo.gvo != null }">
		
		<h1>My group</h1> <p>
<table>
			<tr>
				<td>GroupName</td><td>Leader</td><td>Content</td><td>창립일</td>
			</tr>
				
					<tr>
					<input type="hidden" id="gname" value="${sessionScope.mvo.gvo.gname }">
						<td>${sessionScope.mvo.gvo.gname }</td><td>${sessionScope.mvo.gvo.gleader }</td>
						<td>${sessionScope.mvo.gvo.gcontent }</td><td>${sessionScope.mvo.gvo.gdate }</td>
					</tr>
				
		</table>
		<br>
		
		<c:choose>
		<c:when test="${sessionScope.mvo.gvo.gleader == sessionScope.mvo.id}">
			<input type="button" id="manageGroupBtn" value="그룹 관리하기">
			
		</c:when>
		
		</c:choose>
	
		<input type="button" id="groupmemberBtn" value="그룹 멤버 보기"><br>
		<div id="groupmemberview"></div>
		</c:when>

	<c:otherwise>
	<p> Group List <p>
	<input type="hidden" name="point" id="point2" value="${sessionScope.mvo.point }">
					
		<table>
			<tr>
				<td>GroupName</td><td>Leader</td><td>Content</td><td>Date</td>
			</tr>
				<c:forEach items="${requestScope.gvo }" var="list">
					<tr>
						<td>${list.gname }</td><td>${list.gleader }</td><td>${list.gcontent }</td><td>${list.gdate }</td><td><a href="${initParam.root}/member/groupJoinMember.do?gname=${list.gname}">가입</a></td>
					</tr>
				</c:forEach>
		</table>
		<p>
		<input id="createGroupBtn" type="button" value="그룹만들기"> 
	</c:otherwise>
</c:choose>
<br>
